#include <stdio.h>
#include <stdlib.h>
#include "LinkQueue.h"

#define true 1
#define false 0

//初始化
int LQueue_Init(LQueue* lq)
{
    return DList_Init(&lq->queue);
}

//初始化，返回指针
LQueue* LQueue_Creat()
{
    LQueue* lq;
    lq->queue = *DList_Creat();
    return lq;
}

//遍历队列
void LQueue_Travel(LQueue* lq, PrintCall printCall)
{
    DNode* cur = lq->queue.head;
    while(cur != NULL)
    {
        printCall(cur->data);
        cur = cur->next;
    }
    printf("\n");
}

//入队
void LQueue_Push(LQueue* lq, ElementType element)
{
    DList_InsertTail(&lq->queue, element);
}

//出队
ElementType* LQueue_Pop(LQueue* lq)
{
    if(lq->queue.len == 0)
    {
        printf("Queue is empty!\n");
        return NULL;
    }
    lq->FrontData = lq->queue.head->data;
    DList_RemoveByIndex(&lq->queue, 0);
    return &lq->FrontData;
}

//销毁队列
void LQueue_Destroy(LQueue* lq, DataDestroy dataDestroy)
{
    DList_Destroy(&lq->queue, dataDestroy);
}

//判空
int LQueue_IsEmpty(LQueue* lq)
{
    if(lq->queue.len == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

//获取队首元素
ElementType LQueue_GetFront(LQueue* lq)
{
    return lq->queue.head->data;
}

//获取队列有效元素个数
int LQueue_Size(LQueue* lq)
{
    return lq->queue.len;
}



